<?php
    include "../../php/common.php"; //链接数据库
    $uid = $_POST['uid'];
    $perPage = $_POST['perPage'];
    // 总的数据条数；
    $sql = "SELECT COUNT(c.id) AS c  FROM `carts` AS c JOIN product AS p ON c.pid=p.id 
        JOIN users AS u ON c.uid = u.id JOIN ptype AS pt ON pt.id = p.type 
        WHERE u.id = {$uid}";
    $res =  mysqli_query($link,$sql);           //请求数据库执行查询语句

    $one = mysqli_fetch_assoc($res);            //获取这个结果集
    // print_r($one);
    $totalCount = $one['c'];  // 数据的总条数；结果集中  键名为  c  的字段就是   所有数据的条数

    // 页码的总数；
    $totalPage = ceil($totalCount / $perPage);      //看这些数据分多少页
    // echo $totalPage;
    $arr['totalPage'] = $totalPage;         //   定义一个数组，键名为   totalPage  ，键值为  $totalPage  分页数
    echo json_encode($arr);     //返回这个数组转成json的字符串
?>